class Shot
  
  attr_reader :shot_body, :shot_shape, :x, :y
  
  def initialize(window, source, ang)
    # give it the chipmunk params
    @shot_body = CP::Body.new(0.0001, 0.0001)
    @shot_shape = CP::Shape::Circle.new(@shot_body, 25/2, CP::Vec2.new(0.0, 0.0))
    @shot_anim = Gosu::Image::load_tiles(window, "media/Star.png", 25, 25, false)
    @shot_shape.collision_type = :shot
    @shot_shape.body.p = CP::Vec2.new(source.hero_shape.body.p.to_a[0]-6,
                                      source.hero_shape.body.p.to_a[1]-50) # position
    @shot_shape.body.v = CP::Vec2.new(ang, -500.0) # velocity
    @shot_shape.body.a = (3*Math::PI/2.0) # angle in radians - faces towards top of screen
    
    @x = @shot_shape.body.p.to_a[0]
    @y = @shot_shape.body.p.to_a[1]
    
    # random color definition
    @color = Gosu::Color.new(0xff000000)
    @color.red = rand(255 - 40) + 40
    @color.green = rand(255 - 40) + 40
    @color.blue = rand(255 - 40) + 40
    
    # put it on the playfield
    $space.add_body(@shot_body)
    $space.add_shape(@shot_shape)
  end
  
  def draw  
    img = @shot_anim[Gosu::milliseconds / 100 % @shot_anim.size];
    img.draw(@shot_shape.body.p.to_a[0] - img.width / 2.0,
             @shot_shape.body.p.to_a[1] - img.height / 2.0,
             ZOrder::Stars, 1, 1, @color, :additive)
  end

end